package com.kpmg.datalake.common.dynamicdatasource;

import java.util.HashMap;
import java.util.Map;

/**
 * @author Alex.zhao [alex.zhao@kpmg.com]
 * Created on azhao6 on 2018-06-22 16:55:27
 */
public class DataSourceLocalStoreServiceImpl extends AbstractDataSourceStoreServiceImpl {

    private static Map<String, DatabaseDTO> shardMemoryDataSource = new HashMap<>();

    /**
     * 获取共享的数据源
     *
     * @param dataSourceId dataSourceId
     * @return DatabaseDTO
     */
    @Override
    public DatabaseDTO getShardDataSource(String dataSourceId) {
        return shardMemoryDataSource.get(dataSourceId);
    }

    /**
     * 共享数据源中增加数据
     *
     * @param dataSourceId 数据源ID
     * @param databaseDTO  数据源
     */
    @Override
    public void setShardDataSource(String dataSourceId, DatabaseDTO databaseDTO) {
        shardMemoryDataSource.put(dataSourceId, databaseDTO);
    }

    /**
     * 共享存储中是否存在该数据源
     *
     * @param dataSourceId 数据源ID
     * @return 是否存在
     */
    @Override
    public Boolean containShardDataSourceId(String dataSourceId) {
        return shardMemoryDataSource.containsKey(dataSourceId);
    }
}
